define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'member_money_record/index' + location.search,
                }
            });

            var table = $("#table");
            table.on('load-success.bs.table', function (e, data) {
                var countData = data.extend.count;
                $('#tj').remove();
                var html = '<div id="tj" class="row" style="padding-top: 10px">';
                $.each(countData,function (index,value) {
                    html = html +  '<div class="table-dashboard-item-container form-group col-xs-12 col-sm-6 col-md-3 col-lg-2"><div class="table-dashboard-item-tip"><span class="table-dashboard-item-dot"></span>'+value.name+':</div>'+value.value+'</div>';
                });
                html = html+'</div>'
                $(".fixed-table-body").append(html);
            });

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                commonSearch: true,
                visible: true,
                showToggle: false,
                showColumns: false,
                search:false,
                searchFormVisible:true,
                showExport: true,
                exportTypes: ['excel'],
                exportOptions: {
                    fileName: '客户资金明细_'+ Moment().format("YYYY-MM-DD")
                },
                columns: [
                    [
                        {field: 'id', title: __('Id'),operate: false},
                        {field: 'member_name', title: '用户',operate: 'like'},
                        {field: 'shop_name', title: '商家名称',operate: 'like'},
                        {field: 'nickname', title: '代理商',operate: 'like'},
                        {field: 'detail_type', title: '类别', formatter: Table.api.formatter.status, custom:{1: '充值', 2: '提现',4:'消费',5:'退款',6:'赠送',7:'提现退回'},searchList: {1: '充值', 2: '提现',4:'消费',5:'退款',7:'提现退回'}},
                        {field: 'money', title: '金额',operate: false,sortable: true,formatter: function (value,row) {
                                if (row.type == 1 || row.type == 3){
                                    if (value > 0){
                                        return '+'+value;
                                    } else {
                                        return value;
                                    }
                                }else {
                                    return '-'+value;
                                }
                            }},

                        {field: 'balance', title: '余额',operate: false},
                        {field: 'order_sn', title: '订单号',operate: 'like'},
                        {field: 'remark', title: '备注',operate: 'like'},
                        {field: 'createtime', title: __('Createtime'), operate:false,sortable: true, addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
